package cn.czh.service.impl;

import cn.czh.dao.AdminDao;
import cn.czh.entity.Admin;
import cn.czh.entity.Teacher;
import cn.czh.service.AdminService;
import cn.czh.utils.StringUtils;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author czh
 * @since 2021-05-31
 */
@Service
public class AdminServiceImpl implements AdminService {
    @Autowired
    AdminDao adminDao;

    @Override
    public int login(Admin admin) {
        EntityWrapper<Admin> entityWrapper = new EntityWrapper<>();
        List<Admin> admins = adminDao.selectList(entityWrapper);
        if (admins.size() == 1) {
            Admin byUsername = admins.get(0);
            if (StringUtils.isNotNull(byUsername)) {
                if (byUsername.getPassword().equals(admin.getPassword())) {
                    return 2;
                }
                return 1;
            }
        }
        return 0;
    }
}
